using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_NAME_QUERY_RESPONSE_DEF : DefinitionBase
    {

        public override bool Process()
        {
            ResetPosition();

            if (ClientBuild <= 6803 && ClientBuild > 6803)
                return Process_6803();

            if (ClientBuild <= 8606 && ClientBuild > 6803)
                return Process_8606();

            if (ClientBuild > 8606)
                return Process_10192();


            UInt64 guid = ReadUInt64();
            string name = ReadString(); // 6898 = Name comes first
            string bgrealm = ReadString(); // realm name for cross realm BG usage
            UInt32 race = ReadUInt32();
            UInt32 gender = ReadUInt32();
            UInt32 _class = ReadUInt32();

            if (ClientBuild > 7799)
            {
                byte declined = ReadByte();

                if (declined == 1)
                {
                    for (int i = 0; i < 5; ++i) //MAX_DECLINED_NAME_CASES
                    {
                        string declinename = ReadString();
                    }
                }
            }

            Core.Load_SMSG_NAME_QUERY_RESPONSE(guid, name, bgrealm, race, gender, _class);

            return Validate();
        }


        internal bool Process_6803()
        {
            UInt64 guid = ReadUInt64();
            string bgrealm = ReadString(); // realm name for cross realm BG usage
            string name = ReadString(); // 6898 = Name comes first
            UInt32 race = ReadUInt32();
            UInt32 gender = ReadUInt32();
            UInt32 _class = ReadUInt32();
            if (ClientBuild > 7799)
            {
                byte declined = ReadByte();

                if (declined == 1)
                {
                    for (int i = 0; i < 5; ++i) //MAX_DECLINED_NAME_CASES
                    {
                        string declinename = ReadString();
                    }
                }
            }
            Core.Load_SMSG_NAME_QUERY_RESPONSE(guid, name, bgrealm, race, gender, _class);

            return Validate();
        }

        internal bool Process_8606()
        {
            ResetPosition();
            UInt64 guid = ReadUInt64();
            string name = ReadString(); // 6898 = Name comes first
            string bgrealm = ReadString(); // realm name for cross realm BG usage
            UInt32 race = ReadUInt32();
            UInt32 gender = ReadUInt32();
            UInt32 _class = ReadUInt32();
            if (ClientBuild > 7799)
            {
                byte declined = ReadByte();

                if (declined == 1)
                {
                    for (int i = 0; i < 5; ++i) //MAX_DECLINED_NAME_CASES
                    {
                        string declinename = ReadString();
                    }
                }
            }

            Core.Load_SMSG_NAME_QUERY_RESPONSE(guid, name, bgrealm, race, gender, _class);

            return Validate();
        }

        internal bool Process_10192()
        {
            ResetPosition();

            if (ClientBuild >  9551)
            {
                UInt64 guid = popGuid();

                byte unk = ReadByte(); // added in 3.1
                if (unk != 1)
                {
                    string name = ReadString(); // 6898 = Name comes first
                    string bgrealm = ReadString(); // realm name for cross realm BG usage
                    byte race = ReadByte();
                    byte gender = ReadByte();
                    byte _class = ReadByte();
                    byte declined = ReadByte();

                    if (declined == 1)
                    {
                        for (int i = 0; i < 5; ++i) //MAX_DECLINED_NAME_CASES
                        {
                            string declinename = ReadString();
                        }
                    }



                    Core.Load_SMSG_NAME_QUERY_RESPONSE(guid, name, bgrealm, race, gender, _class);
                }
            }
            else
            {

                UInt64 guid = ReadUInt64();


                string name = ReadString(); // 6898 = Name comes first
                string bgrealm = ReadString(); // realm name for cross realm BG usage
                UInt32 race = ReadUInt32();
                UInt32 gender = ReadUInt32();
                UInt32 _class = ReadUInt32();
                byte declined = ReadByte();

                if (declined == 1)
                {
                    for (int i = 0; i < 5; ++i) //MAX_DECLINED_NAME_CASES
                    {
                        string declinename = ReadString();
                    }
                }



                Core.Load_SMSG_NAME_QUERY_RESPONSE(guid, name, bgrealm, race, gender, _class);

            }
            return Validate();
        }
    }
}
